﻿package bdz.projects.slab.sections {
	import as3.common.ui.menu.core.MenuComponent;
	import as3.common.ui.menu.events.MenuComponentEvent;
	import as3.common.ui.menu.AnimatedItem;
	import bdz.dms.core.DMSGateway;
	import bdz.dms.events.DMSEvent;
	import bdz.dms.vo.SectionVO;
	import bdz.projects.slab.core.SlabSection;
	import bdz.projects.slab.data.SlabSiteData;
	import bdz.projects.slab.managers.SlabSectionManager;
	import flash.events.*;
	import bdz.projects.slab.ui.AllExhibits;
	import bdz.projects.slab.events.SlabSiteEvent;
	import bdz.common.utils.TweenLite;
	import bdz.projects.slab.data.StaticMenuSet;
	import fl.transitions.easing.*;
	import flash.text.*;
	import flash.utils.*;
	/**
	* ...
	* @author Default
	*/
	public class SlabGallery extends SlabSection {
		private var galleryData:SlabSiteData = SlabSiteData.getInstance();
		private var gateway:DMSGateway = DMSGateway.getInstance();
		private var exhibits:AllExhibits;
		private var sdata:SlabSiteData = SlabSiteData.getInstance();
		private var sections:SlabSectionManager;
		private var subMenu:MenuComponent;
		private var activeID:Number;
		private var activeRecord:SectionVO;
		private var activeSection:SlabSection;
		private var _defInfo:SectionVO;
		function SlabGallery() {
			
		}
		private function infoLoaded(evt:SlabSiteEvent):void {
			TweenLite.to(exhibits, .5, { alpha:0, ease:Strong.easeOut, onComplete:createGalleryInfo } );
		}
		private function showGalleryInfo(dta:SectionVO):void {
			activeID = dta.section_id;
			activeRecord = dta as SectionVO;
			sdata.addEventListener(SlabSiteEvent.PUBLIC_GALLERY_INFO_LOADED, createSubMenu);
			if (sdata.getGalleryInfo(dta.section_id) == null) {
				sections.showPreloader();
			}else {
				createSubMenu();
			}
			
		}
		private function onItemClick(evt:SlabSiteEvent):void {
			showGalleryInfo(evt.data);
			TweenLite.to(exhibits, .5, { alpha:0, ease:Strong.easeOut, onComplete:removeChild, onCompleteParams:[exhibits] } );
		}
		private function subMenuClicked(evt:MenuComponentEvent):void {
			switch(evt.data.menu_label.toString()) {
				case "ARTIST WORK":
					activeSection = sections.addSection(SlabArtistWorks, {info:sdata.getGalleryInfo(activeID), ginfo:activeRecord});
				break;
				case "ABOUT THE ARTIST":
					sections.addSection(SlabAboutTheArtist, {artist:SlabArtistWorks(activeSection).activeArtist, gallery:activeRecord});
				break;
				case "ARTIST STATEMENT":
					sections.addSection(SlabAboutTheArtist, {artist:SlabArtistWorks(activeSection).activeArtist, gallery:activeRecord, forStatement:true});
				break;
				case "GALLERY ACTIVITIES":
					sections.addSection(SlabActivityList, { artist:SlabArtistWorks(activeSection).activeArtist, gallery:activeRecord, info:sdata.getGalleryInfo(activeID) } );
				break;
				case "DOCUMENTATION":
					sections.addSection(SlabArtistWorks, {artist:SlabArtistWorks(activeSection).activeArtist, info:sdata.getGalleryInfo(activeID), ginfo:activeRecord, forDocumentation:true});
				break;
				
			}
		}
		private function createSubMenu(evt:* = null):void {
			var tmp = new AnimatedItem(new Object(), new TextFormat());
			tmp = null;
			
			var menuStyle:Object = {embedFonts:true, autoSize:"left", border:false, background:false, backgroundColor:0x222222, antiAliasType:AntiAliasType.NORMAL, gridFitType:GridFitType.PIXEL};
			var menuFontFormat:TextFormat = new TextFormat();
			var fontObj:Object = getDefinitionByName("pixelate");
			menuFontFormat.color = 0x999999;
			menuFontFormat.font = new fontObj().fontName;
			menuFontFormat.size = 10;
			subMenu = new MenuComponent("as3.common.ui.menu.AnimatedItem");
			subMenu.y = 10;
			subMenu.x = 10;
			subMenu.slow_generation = true;
			subMenu.orientation = "horizontal";
			subMenu.labelField = "menu_label";
			subMenu.decoration = "subButtonOver";
			subMenu.outdecoration = "subButtonOut";
			subMenu.menuTextFieldStyle = menuStyle;
			subMenu.menuFontStyle = menuFontFormat;
			subMenu.rollOverColor = 0x000000;
			subMenu.upperCaseLabel = true;
			subMenu.xpad = 25;
			
			subMenu.addEventListener(MenuComponentEvent.CLICK, subMenuClicked);
			addChild(subMenu);
			subMenu.items = StaticMenuSet.GalleryMenu().data_record
			TweenLite.to(exhibits, .5, { alpha:0 } );
			dispatchEvent(new SlabSiteEvent(SlabSiteEvent.PUBLIC_GALLERY_INFO_LOADED));
		}
		private function createGalleryInfo():void {
			
			removeChild(exhibits);
			createSubMenu();
		}
		override protected function initializeComponent(evt:Event):void {
			sections = new SlabSectionManager();
			addChild(sections);
			if(_defInfo == null){
				exhibits = new AllExhibits();
				exhibits.y = 140;
				exhibits.x = 20;
				exhibits.setExhibitData(galleryData.getPublicGalleries());
				exhibits.addEventListener(SlabSiteEvent.ITEM_SELECTED, onItemClick);
				addChild(exhibits);
			}else {
				showGalleryInfo(_defInfo);
			}
			super.initializeComponent(evt);
		}
		public function set defaultInfo(svo:SectionVO):void {
			_defInfo = svo;
		}
		public function get defaultInfo():SectionVO {
			return _defInfo;
		}
	}
	
}